package com.java.base.exercise.util;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @Author RenPu
 * @Date 2022/5/8 15:42
 * @Version 1.0
 * @Description: 反射的工具类
 **/
public class UnsafeInstance {

public static Unsafe getReflectInstance(){
    //利用反射拿到Unsafe对象
    Field theUnsafe = null;
    try {
        theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
        theUnsafe.setAccessible(true);
        return (Unsafe)theUnsafe.get(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;

}


}
